<?php
require("dbFunctions.php");

/**
 * Given a QR Code, update building, floor, floor number,
 * room type and set is_active to true for good measure.
 *
 * Author: Steve Gennaoui
 * Date: 11/21/2012
 */

$qr_code = $_REQUEST['qr_code'];
$building = $_REQUEST['building'];
$floor = $_REQUEST['floor'];
$room_number = $_REQUEST['room_num'];
$room_type = $_REQUEST['room_type'];

if( !is_numeric($qr_code) )
	die("QR Code was non-numeric.");
if( !idIsValid($qr_code,"Room") )
	die("Equipment QR Code was invalid.");
if( is_null($building) )
	die("Building is not provided.");
if( is_null($floor) )
	die("Floor number is not provided.");
if( is_null($room_number) )
	die("Room number is not provided.");
if( is_null($room_type) )
	die("Room type is not provided.");


$dbh = connectDB();

$query = "UPDATE Room SET building=:b,floor=:f,room_number=:rn,room_type=:rt WHERE qr_code=:qr";
$stmt = $dbh->prepare($query);
$stmt->bindParam(':b',$building);
$stmt->bindParam(':f',$floor);
$stmt->bindParam(':rn',$room_number);
$stmt->bindParam(':rt',$room_type);
$stmt->bindParam(':qr',$qr_code);
$stmt->execute();

$query = "UPDATE QR_Code SET is_active=1 WHERE qr_code=:qr";
$stmt = $dbh->prepare($query);
$stmt->bindParam(':qr',$qr_code);
$stmt->execute();

?>
